package com.leeon.generics;

class FixedSizeStack<T>{
	private int index = 0;
	private Object[] storage;
	public FixedSizeStack(int size){
		storage = new Object[size];
	}
	public void push(T item){
		storage[index++] = item;
	}
	@SuppressWarnings("unchecked")
	public T pop(){
		return (T)storage[--index];
	}
	
	public int getLength(){
		return storage.length;
	}
}

public class GenericCast {

	public static final int size = 10;
	public static void main(String[] args){
		FixedSizeStack<String> strings = new FixedSizeStack<String>(size);
		for(String s: "a b c d e f g h j".split(" ")){
			strings.push(s);
		}
		for(int i = 0; i < strings.getLength() - 1; i++){
			String s = strings.pop();
			System.out.print(s + " ");
		}
	}
	
}
